package com.rem.photoablum.dao;

import com.rem.photoablum.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;

/**
 * @author remembrance
 * @version 1.0
 * @date 2022/3/6 21:39
 */
public interface UserDao extends JpaRepository<User,Long> {

    User findByUsernameAndPassword(String username, String password);

    User findByUsername(String username);

    @Transactional
    @Modifying
    @Query(value = "insert into p_user(id,username,password) values(?1,?2,?3) ",nativeQuery = true)
    int addUser(Integer id,String username,String password);

    @Transactional
    @Modifying
    @Query(value = "update p_user set username = :username,password = :password where id =:id",nativeQuery = true)
    int update(String username, String password,Integer id);

    @Transactional
    @Modifying
    @Query(value = "delete from p_user where id =:id",nativeQuery = true)
    int deleteById(Integer id);
}
